import Vue from 'vue'
import peopleInput from '../components/index.vue'
import { deepClone } from '@/utils'
Vue.component('peopleInput', peopleInput)

export function allDialogForm() {
  const validatorActiveName = (rule, data, callback) => {
    const parms = deepClone(data)
    let v1 = []
    let v2 = []
    let v3 = []
    parms.forEach((item, index) => {
      const rule =
        item.v1 === 3
          ? item.v1 === '' || item.day === ''
          : item.v1 === '' || item.v2 === '' || item.day === ''
      if (rule) {
        return callback(new Error('定义选项不能为空'))
      }
      if (item.v1 === 1) {
        v1.push(item.v2)

        const nodeV1 = v1.map(value => value)
        const setV1 = new Set(nodeV1)
        if (nodeV1.length !== setV1.size) {
          return callback(new Error('定义条件不能重复'))
        }
      }
      if (item.v1 === 2) {
        v2.push(item.v2)

        const nodeV2 = parms.map(value => value)
        const setV2 = new Set(nodeV2)
        if (nodeV2.length !== setV2.size) {
          return callback(new Error('定义条件不能重复'))
        }
      }
      if (item.v1 === 3) {
        v3.push(item.v1)
        if (v3.length > 1) {
          return callback(new Error('定义条件不能重复'))
        }
      }
    })

    callback()
  }
  return [
    {
      label: '人群名称',
      prop: 'name',
    },
    {
      label: '人群定义',
      prop: 'peopleType',
      component: peopleInput,
      params: {},
      rules: [
        {
          required: true,
          validator: validatorActiveName,
          // message: '请选择活动名称',
        },
      ],
    },
  ]
}
